﻿using System;
using System.Drawing;
using MUnit;

namespace Maze
{
    class TestPathFinder
    {
        SQ[,] squares = {{ SQ.O, SQ.O, SQ.O },
                         { SQ.O, SQ.W, SQ.O }};
        Board board;
        PathFinder pathFinder;

        [Setup]
        void Setup()
        {
            // This will be run once before each test method
            board = new Board(this.squares);
            pathFinder = new PathFinder(board);
        }

        [Test]
        void NoPath()
        {
            Verify.Equals(0, pathFinder.CurrentPath.Count);
        }

        private void CheckPath(Point[] points)
        {
            foreach (Point p in points)
            {
                Verify.Equals(p, pathFinder.CurrentPath.First.Value);
                pathFinder.CurrentPath.RemoveFirst();
            }
        }

        [Test]
        void FindPath()
        {
            Point start = new Point(0, 1);
            Point destination = new Point(2, 1);
            pathFinder.Find(start, destination);

            Verify.Equals(4, pathFinder.CurrentPath.Count);
            Point[] path = { new Point(0, 0), new Point(1, 0), new Point(2, 0), destination };
            this.CheckPath(path);
        }

        [Test]
        void FindPathTwice()
        {
            Point start = new Point(0, 1);
            Point destination = new Point(1, 0);
            pathFinder.Find(start, destination);
            pathFinder.Find(destination, start);

            Verify.Equals(4, pathFinder.CurrentPath.Count);
            Point[] path = { new Point(0, 0), destination, new Point(0, 0), start };
            this.CheckPath(path);
        }

        [Test]
        void PointIsValid1()
        {
            Verify.Assert(pathFinder.IsValid(new Point(0, 0)));
        }

        [Test]
        void PointIsValid2()
        {
            Verify.Assert(pathFinder.IsValid(new Point(1, 0)));
        }

        [Test]
        void PointIsInvalid1()
        {
            Verify.Assert(!pathFinder.IsValid(new Point(-1, 0)));
        }
        [Test]
        void PointIsInvalid2()
        {
            Verify.Assert(!pathFinder.IsValid(new Point(0, -1)));
        }
        [Test]
        void PointIsInvalid3()
        {
            Verify.Assert(!pathFinder.IsValid(new Point(3, 0)));
        }
        [Test]
        void PointIsInvalid4()
        {
            Verify.Assert(!pathFinder.IsValid(new Point(0, 2)));
        }

        
        [Test]
        void PossiblePoints()
        {
            this.pathFinder.AddPossibleAlternatives(new Point(0, 0));
            Verify.Equals(2, this.pathFinder.Queue.Count);
        }
        
        [TearDown]
        void TearDown()
        {
            // This will be run once after each test method
        }
    }
}
